package com.systop.ltbook.sms.smscfg.webapp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.systop.core.webapp.struts2.action.BaseAction;
import com.systop.ltbook.sms.smscfg.model.SmsCfg;
import com.systop.ltbook.sms.smscfg.service.SmsCfgManager;

/**
 * 短息发送条数管理的struts2 Action。
 * @author DU
 */
@SuppressWarnings("serial")
@Controller
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class SmsCfgAction extends BaseAction implements ModelDriven<SmsCfg> {

	private SmsCfg model = new SmsCfg();
	
	@Autowired(required=true)
	private SmsCfgManager smsCfgManager;
	
	/**
   * 进入短信配置编辑页面
   * @return
   */
  public String edit() {
    model = smsCfgManager.get();
    if(model == null) {
      model = new SmsCfg();
    }
    
    return "input";
  }

  /**
   * 保存短信配置信息
   * @return
   */
  public String save() {
    try{
    	smsCfgManager.save(model);
      addActionMessage("短信发送条数配置成功！");
      return "success";
    }catch (Exception e) {
      addActionError(e.getMessage());
    }
    return "input";
  }
  
	public SmsCfg getModel() {
  	return model;
  }

	public void setModel(SmsCfg model) {
  	this.model = model;
  }
}
